package com.effectiv.gooruda.rest.api.controller;

import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.PagedList;
import org.springframework.social.facebook.api.Question;
import org.springframework.social.facebook.api.QuestionOption;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/api/facebook/question")

public class FacebookQuestionOperations {

	@RequestMapping(value = "/addoption/{questionId}", method = RequestMethod.POST)
	public String addOption(String questionId, String optionText, Facebook facebook) {
		return facebook.questionOperations().addOption(questionId, optionText);
	}

	@RequestMapping(value = "/askquestion/{questionText}", method = RequestMethod.GET)
	public String askQuestion(String questionText, Facebook facebook) {
		return facebook.questionOperations().askQuestion(questionText);
	}

	@RequestMapping(value = "/deleteoption/{optionId}", method = RequestMethod.DELETE)
	public void deleteOption(String optionId, Facebook facebook) {
		facebook.questionOperations().deleteOption(optionId);
	}

	@RequestMapping(value = "/deletequestion/{questionId}", method = RequestMethod.DELETE)
	public void deleteQuestion(String questionId, Facebook facebook) {
		facebook.questionOperations().deleteQuestion(questionId);
	}

	@RequestMapping(value = "/getoption/{optionId}", method = RequestMethod.GET)
	public QuestionOption getOption(String optionId, Facebook facebook) {
		return facebook.questionOperations().getOption(optionId);
	}

	@RequestMapping(value = "/getoptions/{questionId}", method = RequestMethod.GET)
	public PagedList<QuestionOption> getOptions(String questionId, Facebook facebook) {
		return facebook.questionOperations().getOptions(questionId);
	}

	@RequestMapping(value = "/getquestion/{questionId}", method = RequestMethod.GET)
	public Question getQuestion(String questionId, Facebook facebook) {
		return facebook.questionOperations().getQuestion(questionId);
	}

	@RequestMapping(value = "/getquestions", method = RequestMethod.GET)
	public PagedList<Question> getQuestions(Facebook facebook) {
		return facebook.questionOperations().getQuestions();
	}

	@RequestMapping(value = "/getquestions/{userId}", method = RequestMethod.GET)
	public PagedList<Question> getQuestions(String userId, Facebook facebook) {
		return facebook.questionOperations().getQuestions(userId);
	}

}
